const BaseRest = require('../rest.js');

module.exports = class extends BaseRest {
  indexAction() {
    return this.display();
  }

  async userListAction() {
    const {page,pageSize, key, value} = this.ctx.query;
    const user = this.model('user');
    let where = {[key]: value}
    if (!value || value === '') {
      where = {}
    }
    const userPage = await user.where(where).page(page,pageSize).countSelect();
    this.success(userPage);
  }

  async resetPassword() {
    const {userId} = this.post();
    const user = await this.modelInstance.where({id: userId}).find();
    const id_card = user.id_card.substr(user.id_card.length-6);
    user.password = this.encrypt(id_card);
    const row = this.modelInstance.update(user);
    this.success(row);
  }
};
